package com.example.demo01.VO;


import cn.hutool.core.util.ByteUtil;
import cn.hutool.core.util.HexUtil;
import com.example.demo01.Utils.ArrayUtils;

import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public abstract class BasePacketInstruction implements  IPacketInstruction{


    protected void setBytes(byte[] bytes) {
        this.bytes = bytes;
    }

    /**
     * 电文号
     */
    protected String telNo;

    /**
     * 字节
     */

    protected byte[] bytes=new byte[0];


    protected byte[] body=new byte[0];



    @Override
    public String getTelNo() {
        return this.telNo;
    }

    protected void setTelNo(String telNo) {
        this.telNo = telNo;
    }
    @Override
    public byte[] getBytes() {


        return  this.bytes;
    }


    public byte[] getBody() {
        return body;
    }

    public void setBody(byte[] body) {
        this.body = body;
        short len=(short) body.length;
        len= (short) (len+2);
//
        byte[] header_byte= ByteUtil.shortToBytes(len, ByteOrder.BIG_ENDIAN);

        byte[] body_content= ArrayUtils.concatByte(header_byte,body);
//        byte[] body_content=new byte[header_byte.length+body.length];
//
//
//        System.arraycopy(header_byte,0,body_content,0, header_byte.length);
//
//        System.arraycopy(body,0,body_content,header_byte.length, body.length);

        setBytes(body_content);

    }
}
